package sliver.action.advertisement;

import java.util.List;
import java.util.Map;

import org.apache.struts2.interceptor.RequestAware;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import sliver.entity.Province;
import sliver.entity.Tag;
import sliver.service.ProvinceManager;
import sliver.service.TagManager;

import com.opensymphony.xwork2.ActionSupport;

@Scope("prototype")
@Controller("advertisement.toAddAdvertisementAction")
public class ToAddAdvertisementAction extends ActionSupport implements RequestAware{
	
	private static final long serialVersionUID = 6889729584253327053L;
	
	private Map<String, Object> request;
	
	@Autowired
	private TagManager tagManager;
	
	@Autowired
	private ProvinceManager provinceManager;
	
	@Override
	public void setRequest(Map<String, Object> request) {
		this.request = request;
	}
	
	@Override
	public String execute() throws Exception {
		
		List<Tag> tags = tagManager.obtainAllTags();
		List<Province> provinces = provinceManager.obtainAllProvince();
		request.put("tags", tags);
		request.put("provinces", provinces);
		
		System.out.println(provinces.size());
		
		return SUCCESS;
	}
	
}